<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>一只小初尘</title>
	<link rel="shortcut icon" type="image/vnd.microsoft.icon" href="./else/ico7.ico" />
	<link rel="stylesheet" href="./css/index.css">
	<script src="js/jQuery.js"></script>
	<!-- <script src="https://gitee.com/love-your-yu/love/raw/master/storage.js"></script> -->
	<script src="./js/storage.js"></script>
</head>

<body>
	<input id="cx" class="Btn" placeholder="请输入学生姓名" value=""></input>
	<div id="one">没有可以匹配的值</div>
	<script>
		window.onerror = function () { return true; } // 禁止浏览器的报错提示
        //用于判断输入中文时触发监听时间
        var doing = false;
        document.getElementById('cx').addEventListener('compositionstart', function (e) {
            doing = true;
        }, false);
        document.getElementById('cx').addEventListener('input', function (e) {
            if (!doing) {
                one();
            }
        }, false);

        document.getElementById('cx').addEventListener('compositionend', function (e) {
            doing = false;
            one();
        }, false);
        function one() {
            let jsonfh = [];
            for (let i = 0; i < storage.length; i++) { //遍历数组要查询的数组
                var leng = storage[i].name.split(""); // 如果要修改要查询哪一项的时候需要修改这行代码
                var cx = document.getElementById("cx").value.split(""); // 输入框的id
                for (let a = 0; a < cx.length; a++) {
                    for (let b = 0; b < leng.length; b++) {
                        if (cx[a] == leng[b]) {
                            jsonfh.push(
                                `${storage[i].name},${storage[i].state}`
                            );
                        }
                    }
                }
                jsonfh = Array.from(new Set(jsonfh)); //数组去重
            }
            document.getElementById("one").innerHTML = "";
            for (var c = 0; c < jsonfh.length; c++) {
                var text = jsonfh[c].split(",");
                // let div = document.createElement("div");
                // div.classList = "menu";
                // div.innerHTML =
                //     `<span>名称: <font class='name'>${text[0]}</font></span>`;
                // document.getElementById("one").appendChild(div);
                for (var a = 0; a < storage.length; a++) {
                    if (text[0] == storage[a].name && text[1] == "0") {
                        console.log(a);
                        $("#one").append(`
                                <div class="menu">
                                    <h1 class="label">${text[0]}</h1>
                                    <div class="ves"></div>
                                </div>
                            `);
                        for (var aa = 0; aa < storage[a].mv.length; aa++) {
                            let name = storage[a].name;
                            let sum = storage[a].mv[aa].split("|")[0];
                            let src = storage[a].mv[aa].split("|")[1];
                            $(".ves").eq(a).append(`
                                <span class="test" title="${sum}" data-name="${name + "," + sum}" data-src="${src}">
                                    ${sum}
                                </span>
                            `);
                        }
                    }
                }
            }
            if (document.getElementById("cx").value.length == 0) {
                for (var a = 0; a < storage.length; a++) {
                    if (storage[a].state == "0") {
                        $("#one").append(`
                            <div class="menu">
                                <h1 class="label">${storage[a].name}</h1>
                                <div class="ves"></div>
                            </div>
                        `);
                        for (var aa = 0; aa < storage[a].mv.length; aa++) {
                            let name = storage[a].name;
                            let sum = storage[a].mv[aa].split("|")[0];
                            let src = storage[a].mv[aa].split("|")[1];
                            $(".menu .ves").eq(a).append(`
                                <span class="test" title="${sum}" data-name="${name + "," + sum}" data-src="${src}">
                                    ${sum}
                                </span>
                            `);
                        }
                    }
                }
            }
            else if (jsonfh.length == 0) {
                document.getElementById("one").innerHTML = "抱歉~没有查询到";
            }
            return jsonfh;
        }
        one();
	</script>
	<script>
		// $(".menu .ves .test").click(function () {
        $(document).on("click",".menu .ves .test",function(){
            let name = $(this).attr("data-name").split(",")[0];
            let num = $(this).attr("data-name").split(",")[1];
            let src = $(this).attr("data-src");
            window.sessionStorage.mvsrc = `${name + " " + num},${src}`;
            window.open("./else/mv.html");
        });
	</script>
</body>

</html>